<template>
<div class="we-chat-applets-channel-add views-container">
    <div class="wlm-form">
        <div class="wlm-form-notice warning">
            <p>一个平台只可以绑定一个微信小程序，如未注册微信小程序，请注册<a target="_blank" href="https://mp.weixin.qq.com/" class="alink-blue">去注册</a></p>
            <!-- <p>你的平台已经获得了该小程序所有的接口权限，可以正常对接微信，如发现使用中接口有异常，请点此 <router-link tag="span" to="/user/managementUser">
          <el-button type="text" class="orders-red">重新授权</el-button>
        </router-link>
      </p>
      <p>点击<router-link tag="span" to="/user/managementUser">
          <el-button type="text" class="orders-red">授权</el-button>
        </router-link>是否成功</p> -->
        </div>
        <div class="flex-row" style="padding:10px 20px 50px;">
            <div class="wlm-form-content">
                <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="220px" class="retail-form" label-position="right">
                    <el-form-item label="小程序名称" prop="username">
                        <el-input v-model="formFormatData.formData.channel.sapp.name"></el-input>
                    </el-form-item>
                    <el-form-item label="AppId" prop="password">
                        <el-input v-model="formFormatData.formData.channel.sapp.AppId"></el-input>
                    </el-form-item>
                    <el-form-item label="AppSecret" prop="repassword">
                        <el-input v-model="formFormatData.formData.channel.sapp.AppSecret"></el-input>
                    </el-form-item>
                    <el-form-item label="原始ID" prop="repassword">
                        <el-input v-model="formFormatData.formData.channel.sapp.original"></el-input>
                    </el-form-item>
                    <el-form-item label="小程序LOGO" prop="repassword">
                        <!-- <upload ref="uploadplatform" :config="uploadLogoConfig" :changeEvt="formFormatFiltersChange"></upload> -->
                        <choose-files ref="chooseFiles" :config="chooseLogoConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                        <div class="form-help">建议尺寸：100*100px</div>
                    </el-form-item>
                    <el-form-item label="二维码" prop="repassword" class="slider">
                        <!-- <upload ref="uploadplatform" :config="uploadQrConfig" :changeEvt="formFormatFiltersChange"></upload> -->
                        <choose-files ref="chooseFiles" :config="chooseBgConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                        <div class="form-help">建议尺寸：100*100px</div>
                    </el-form-item>
                    <el-form-item label="EncodingAESKey(消息加密密钥)">
                        <el-input v-model="formFormatData.formData.channel.sapp.authorized.EncodingAESKey"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
    <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
        <el-button size="small" @click="formFormatSubmit({ router: { type: 'replace', path: '/channel/weChatAppletsChannel', code: 1 }})" type="primary">保存</el-button>
    </div>
</div>
</template>

<script>
// import { userAdd } from '@/api/user'
// import upload from '@/components/Upload/index'
import ChooseFiles from '@/components/ChooseFiles/index'
import {
  channelSave
} from '@/api/channel'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Form')],
  name: 'WeChatAppletsChannelAdd',
  components: {
    // upload
    ChooseFiles
  },
  directives: {

  },
  data() {
    return {
      // uploadLogoConfig: {
      //   type: ['image'],
      //   initList: [],
      //   bindKey: {
      //     key: 'channel|sapp|logo',
      //     model: 'img'
      //   }
      // },
      // uploadQrConfig: {
      //   type: ['image'],
      //   initList: [],
      //   bindKey: {
      //     key: 'channel|sapp|qrcode',
      //     model: 'img'
      //   }
      // },
      chooseLogoConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          model: 'display'
        },
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'channel|sapp|logo',
          model: 'img'
          // validateField: 'merchantlog'
        }
      },
      chooseBgConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isMore: true,
          model: 'display'
        },
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'channel|sapp|qrcode',
          model: 'img'
          // validateField: 'businessbackgroundmap'
        }
      },
      formFormatData: {
        key: 'userForm',
        api: {
          editForm: {
            api: channelSave,
            params: {

            },
            filters: {
              img: {
                bindInit: ['chooseLogoConfig', 'chooseBgConfig']
              }
            },
            always: true
          },
          submitForm: channelSave
        },
        formData: {
          type: 'sapp',
          channel: {
            sapp: {
              name: '',
              AppId: '',
              AppSecret: '',
              logo: [],
              original: '',
              qrcode: [],
              authorized: { EncodingAESKey: '' },
              switch: '0'
            }
          }
        },
        rules: {

        }
      }
    }
  },
  methods: {

  }
}
</script>

<style lang="scss" scoped>
.we-chat-applets-channel-add {}
</style>
